/**
 *
 */
package org.insia.smartposse.test;

import org.insia.smartposse.manager.ApplicationManager;
import org.insia.smartposse.manager.CategorieManager;
import org.insia.smartposse.manager.FreelanceBookManager;
import org.insia.smartposse.manager.FreelanceSkillManager;
import org.insia.smartposse.manager.JobProjectManager;
import org.insia.smartposse.manager.ProjectManager;
import org.insia.smartposse.manager.SkillManager;
import org.insia.smartposse.manager.UserManager;
import org.insia.smartposse.mapping.dao._RootDAO;

/**
 * @author cmougel This Class add value in Database for have a begin Information
 */
public class CreateValueInDatabase
{

	private static Integer _jobProjectManagerId6;
	private static Integer _userId2;

	/**
	 * Add value in database
	 */
	public void addValues() {


		/**
		 * Creation of Skill
		 */
		SkillManager s = new SkillManager();
		s.setName("J2EE");
		s.save();

		SkillManager s1 = new SkillManager();
		s1.setName("C#");
		s1.save();

		SkillManager s2 = new SkillManager();
		s2.setName("PHP");
		s2.save();


		SkillManager s3 = new SkillManager();
		s3.setName("WebDesign");
		s3.save();

		/**
		 * Creation of User
		 */

		UserManager u = new UserManager();
		u.setLogin("manager_first");
		u.setFirstName("first");
		u.setLastName("first_last");
		u.setPassword("password");
		u.setManager(true);
		u.save();

		UserManager u2 = new UserManager();
		u2.setLogin("manager_second");
		u2.setFirstName("second");
		u2.setLastName("second_last");
		u2.setPassword("second");
		u2.setManager(true);
		u2.setFreelance(true);
		u2.setEmail("cmougel@insia.org");
		u2.save();

		_userId2 = u2.getId();

		/**
		 * Freelance Book of U2
		 */
		FreelanceBookManager fb = new FreelanceBookManager();
		fb.setURL("http://premierbook.manager_second");
		fb.setComment("very good first book of Manager Second");
		fb.setFreelance(u2);
		fb.save();

		FreelanceBookManager fb1 = new FreelanceBookManager();
		fb1.setURL("http://secondbook.manager_second");
		fb1.setComment("very good second book of Manager Second");
		fb1.setFreelance(u2);
		fb1.save();

		FreelanceSkillManager fs = new FreelanceSkillManager();
		fs.setGrade(1);
		fs.setComment("very cool");
		fs.setSkill(s1);
		fs.setRanking(1);
		fs.setFreelance(u2);
		fs.save();

		UserManager u3 = new UserManager();
		u3.setLogin("freelance_first");
		u3.setFirstName("third");
		u3.setLastName("third_last");
		u3.setPassword("first");
		u3.setFreelance(true);
		u3.save();

		FreelanceBookManager fb2 = new FreelanceBookManager();
		fb2.setURL("http://book.freelance_first");
		fb2.setComment("very bad first book of First Freelance");
		fb2.setFreelance(u3);
		fb2.save();

		FreelanceSkillManager fs1 = new FreelanceSkillManager();
		fs1.setGrade(5);
		fs1.setComment("I love it and I am the best");
		fs1.setSkill(s);
		fs1.setRanking(1);
		fs1.setFreelance(u3);
		fs1.save();

		FreelanceSkillManager fs2 = new FreelanceSkillManager();
		fs2.setGrade(1);
		fs2.setComment("I love that, but I am not good");
		fs2.setSkill(s2);
		fs2.setRanking(2);
		fs2.setFreelance(u3);
		fs2.save();

		FreelanceSkillManager fs3 = new FreelanceSkillManager();
		fs3.setGrade(3);
		fs3.setComment("maybe yes, maybe no");
		fs3.setSkill(s3);
		fs3.setRanking(3);
		fs3.setFreelance(u3);
		fs3.save();

		/**
		 * Create Categorie
		 */
		CategorieManager c1 = new CategorieManager();
		c1.setName("first_categorie");
		c1.save();

		CategorieManager c2 = new CategorieManager();
		c2.setName("second_categorie");
		c2.save();

		/**
		 * Create Project
		 */


		/**
		 * First Project
		 */
		ProjectManager p1 = new ProjectManager();
		p1.setManager(u);
		p1.setCategory(c1);
		p1.setShortDescription("a good first project");
		p1.setSubject("First Project");
		p1.save();


		/**
		 * First job for first Project
		 */
		JobProjectManager jp1 = new JobProjectManager();
		jp1.setProject(p1);
		jp1.setSkill(s);
		jp1.save();


		/**
		 * Second Job for First Project
		 */
		JobProjectManager jp3 = new JobProjectManager();
		jp3.setProject(p1);
		jp3.setSkill(s3);
		jp3.save();

		/**
		 * Third job for first Project (complete
		 */
		JobProjectManager jp4 = new JobProjectManager();
		jp4.setProject(p1);
		jp4.setSkill(s2);
		jp4.save();

		JobProjectManager jp5 = new JobProjectManager();
		jp5.setProject(p1);
		jp5.setSkill(s);
		jp5.setFreelance(u2);
		jp5.save();


		/**
		 * Second Project
		 */
		ProjectManager p2 = new ProjectManager();
		p2.setManager(u2);
		p2.setCategory(c2);
		p2.setShortDescription("A good second project");
		p2.setSubject("Second Project");
		p2.save();

		/**
		 * First Job for Second Project
		 */
		JobProjectManager jp2 = new JobProjectManager();
		jp2.setProject(p2);
		jp2.setSkill(s2);
		jp2.save();


		/**
		 * Third Project
		 */
		ProjectManager p3 = new ProjectManager();
		p3.setManager(u);
		p3.setCategory(c1);
		p3.setShortDescription("a good third complete project");
		p3.setSubject("Complete Project");
		p3.save();

		JobProjectManager jp6 = new JobProjectManager();
		jp6.setProject(p3);
		jp6.setSkill(s2);
		jp6.save();

		_jobProjectManagerId6 = jp6.getId();

		/**
		 * Four Project
		 */
		ProjectManager p4 = new ProjectManager();
		p4.setManager(u2);
		p4.setCategory(c1);
		p4.setShortDescription("a four incomplete project");
		p4.setSubject("Complete Project");
		p4.save();

		/**
		 * Application
		 */
		ApplicationManager am = new ApplicationManager();
		am.setFreelance(u2);
		am.setJobProject(jp1);
		am.setFrom(ApplicationManager.FREELANCEFROM);
		am.setMessage("I am very interresting");
		am.setAccept(ApplicationManager.REFUSED);
		am.setSalary(300);
		am.save();

		ApplicationManager am1 = new ApplicationManager();
		am1.setFreelance(u2);
		am1.setJobProject(jp1);
		am1.setFrom(ApplicationManager.MANAGERFROM);
		am1.setMessage("Why not ?");
		am1.setSalary(300);
		am1.save();

		ApplicationManager am2 = new ApplicationManager();
		am2.setFreelance(u3);
		am2.setJobProject(jp1);
		am2.setFrom(ApplicationManager.FREELANCEFROM);
		am2.setMessage("Very Good");
		am2.setSalary(100);
		am2.setAccept(ApplicationManager.ACCEPT);
		am2.save();

	} // addValues

	public void closeProject(){

		UserManager u2 = new UserManager(_userId2);

		JobProjectManager jp6 = new JobProjectManager(_jobProjectManagerId6);
		jp6.setFreelance(u2);
		jp6.save();
	}

	/**
	 * Start the addValues
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		CreateValueInDatabase c = new CreateValueInDatabase();
		_RootDAO.initialize();
		c.addValues();
		_RootDAO.closeCurrentSession();
		c.closeProject();
		_RootDAO.closeCurrentSession();
	}

}
